package com.pfzy.utildemo.activity.record.soundrecord.helper;

import androidx.annotation.Nullable;

//import com.pfzy.sdk.soundrecord.SoundRecordCallback;
//import com.pfzy.sdk.soundrecord.constatns.CallbackConstant;

import com.pfzy.utildemo.activity.record.soundrecord.RecordingInfo;
import com.pfzy.utildemo.activity.record.soundrecord.SoundRecordCallback;
import com.pfzy.utildemo.activity.record.soundrecord.constatns.CallbackConstant;

import java.util.HashMap;
import java.util.Map;

/**
 * 回调工具
 */
public class CallBackHelper {
    public static SoundRecordCallback sCallBack = null;

    /**
     * 执行失败
     */
    public static void execOnFail(RecordingInfo info, String failInfo, SoundRecordCallback callback) {
        if (callback != null) {
            callback.onFail(info, failInfo);
        }
    }

    /**
     * 执行失败 并且 清理 和 设置 正在录制种
     */
    public static void execOnFailAndClearAndSetIsRecording(RecordingInfo info, String failInfo) {
        if (sCallBack != null) {
            sCallBack.onFail(info, failInfo);
        }
        sCallBack = null;
    }

    /**
     * 开始录音 并 设置正在录制种
      */
    public static void execOnStartAndSetIsRecording(RecordingInfo info) {
        if (sCallBack != null) {
            sCallBack.onStart(info);
        }
    }

    /**
     * 执行停止 + 清理 + 正在录制
     * @param info
     * @param stopInfo
     */
    public static void execOnStopAndClearAndSetIsRecording(RecordingInfo info, String stopInfo) {
        execOnStopAndClearAndSetIsRecording(info, stopInfo, null);
    }

    /**
     * 执行停止 + 清理 + 正在录制
     * @param info
     * @param stopInfo
     * @param e
     */
    public static void execOnStopAndClearAndSetIsRecording(RecordingInfo info, String stopInfo, @Nullable Exception e) {
        if (sCallBack != null) {
            Map<String, String> map = new HashMap<>();
            map.put(CallbackConstant.ResultValue.StopInfo.value(), stopInfo);
            if (e != null) {
                map.put(CallbackConstant.ResultValue.ExceptionStackInfo.value(), e.toString());
            }
            sCallBack.onStop(info, map);
        }
        sCallBack = null;
    }
}
